package com.imagination.applet.domain.product.repository;

import com.imagination.applet.domain.product.model.ProductImage;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProductImageRepository extends JpaRepository<ProductImage, Long> {

    Page<ProductImage> findAllByUserIdAndDeleted(Long userId, Integer deleted, Pageable pageable);

    List<ProductImage> getByTaskIdAndDeleted(String taskId, Integer deleted);

    List<ProductImage> getByTrainingStatus(Integer trainingStatus);

    @Query(value = "select count(1) from t_product_images where deleted = 0 and user_id = :userId and channel_type in (:channelTypes)",nativeQuery = true)
    Integer queryCount(@Param("userId")Long userId,@Param("channelTypes") List<String> channelTypes);

    @Query(value = "SELECT * FROM t_product_images WHERE deleted = 0 and user_id = :userId and channel_type in (:channelTypes) "
            ,countQuery = "SELECT count(1) FROM t_product_images WHERE deleted = 0 and user_id = :userId and channel_type in (:channelTypes)"
    ,nativeQuery = true
    )
    Page<ProductImage> findByPageable(@Param("userId")Long userId, @Param("channelTypes")  List<String> channelTypes, Pageable pageable);
}
